<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/5/29
 * Time: 22:34
 */

namespace Admin\Policies;


use Platform\Models\Admin\Administrator;
use Platform\System\Tools\ResultTool;

class AdminPolicy
{

    /**
     * 判断是否可以更新此管理员信息
     * @param Administrator $admin
     * @param Administrator $admin_target
     * @return bool
     */
    public function update(Administrator $admin,Administrator $admin_target)
    {
        if ($admin->isAdmin()) return true;
        if ($admin->id === $admin_target->id){
            return true;
        };
        myResult()->stop(ResultTool::CODE_NO_RIGHT);
    }

    /**
     * 判断是否可以删除此管理员
     * @param Administrator $admin
     * @param Administrator $admin_target
     * @return bool
     */
    public function destroy(Administrator $admin,Administrator $admin_target)
    {
        if ($admin_target->isAdmin()) myResult()->stop(ResultTool::CODE_TARGET_WRONG,'超级管理员不可删除');
        if ($admin->isAdmin()) return true;
        if ($admin->id === $admin_target->id) myResult()->stop(ResultTool::CODE_TARGET_WRONG,'不可删除自己');

        myResult()->stop(ResultTool::CODE_NO_RIGHT);
    }
}